<!-- ************************************************************************************************************ -->
<!-- fileName          : admin_postsright.jsp 																	  -->
<!-- summary           : admin端  “文章列表（右）” 相关编辑 														  		  -->
<!-- ************************************************************************************************************ -->

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>admin_postsright</title>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../js/validator.js"></script>
<script type="text/javascript">
$.ajaxSetup ({
   	cache: false //关闭AJAX相应的缓存
});
</script>
<style type="text/css">
body{
background-image:url(../../image/admin_bg.png);
background-repeat:repeat-x;
margin-left: 0px;
margin-top: 0px;
margin-right: 1px;
margin-bottom: 0px;
font-family:Microsoft YaHei;
font-size:13px;
}
h2{
font-family:Microsoft YaHei;
color:#fff;
margin: 5px 5px 5px 5px;
font-size:16px;
}

</style>
</head>
<body>

<%
	int intPageSize; //一页显示的记录数 
	int intRowCount; //记录总数 
	int intPageCount; //总页数 
	int intPage; //待显示页码 
	String strPage; 
	
	//设置一页显示的记录数 
	intPageSize = 34; 
	
	//取得待显示页码 
	strPage = request.getParameter("page"); 
	if(strPage==null){//表明在QueryString中没有page这一个参数，此时显示第一页数据 
		intPage = 1; 
	}
	else{//将字符串转换成整型 
		intPage = java.lang.Integer.parseInt(strPage); 
		if(intPage< 1){ 
			intPage = 1; 
		} 
	} 

	//设置请求的字符编码以支持中文
	request.setCharacterEncoding ("utf-8");

	//获取请求参数

	//从web.xml获取全局参数
	String drv=config.getServletContext().getInitParameter("DBDriver");
	String url=config.getServletContext().getInitParameter("DBURL");
	String uid=config.getServletContext().getInitParameter("DBUser");
	String pwd=config.getServletContext().getInitParameter("DBPass");
	
	//构建SQL字符串和JDBC对象
	String strSQL1 = "SELECT * FROM immie0_immi.postsright  where name='Title+' and content_name='Title-' ";		//id name content_name content date
	String strSQL2 = "SELECT * FROM immie0_immi.postsright  where name!='Title+' and content_name!='Title-' order by date desc ";		//id name content_name content date
	Connection conn = null;
	PreparedStatement pstmt1 = null;	
	PreparedStatement pstmt2 = null;	
	ResultSet rs1 = null;	//列表标题
	ResultSet rs2 = null;	//所有文章
	
	try {
		Class.forName(drv).newInstance();
		conn = DriverManager.getConnection(url,uid,pwd);
		pstmt1 = conn.prepareStatement(strSQL1);
		rs1 = pstmt1.executeQuery();
		
		pstmt2 = conn.prepareStatement(strSQL2);
		
		rs2 = pstmt2.executeQuery();
		rs2.absolute(1); 
		
		//获取记录总数 
		rs2.last(); 
		intRowCount = rs2.getRow(); 

		//记算总页数 
		intPageCount = (intRowCount+intPageSize-1) / intPageSize; 

		//调整待显示的页码 
		if(intPage >intPageCount) intPage = intPageCount; 
%>
<h2>编辑文章列表（右）</h2>
<div style="margin:0 auto;width:770px">
<%	
		if(intPageCount >0){ 
%>
	<div style="height:850px;margin-top:10px;">
	<table  style="table-layout:fixed;" >
		<tr>
			<th></th>
			<%if(rs1.next()){%>
			<th width="600px"><%=rs1.getString(4) %></th>
			<%}
			else{%>
			<th width="600px">文章列表</th>
			<%} %>
			<th>时间</th>
			<th colspan="2" >操作</th> 
		</tr>
<%
			//将记录指针定位到待显示页的第一条记录上 
			rs2.absolute((intPage-1) * intPageSize+1); 
			//显示数据 
			int i = 0; 
			
			while(i< intPageSize && !rs2.isAfterLast()){ 	%>
			<tr >
				<td style="word-break:keep-all; border-bottom: #6666cc 1px dashed;"><%=i+1 %></td>
			  	<td style="word-break:keep-all;/* 不换行 */white-space:nowrap;/* 不换行 */overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用。*/ border-bottom: #6666cc 1px dashed;"><font><%=rs2.getString(2) %></font></td>
				<td style="word-break:keep-all; border-bottom: #6666cc 1px dashed;margin:auto;"><%=rs2.getDate(5) %></td>
				<td style="word-break:keep-all; border-bottom: #6666cc 1px dashed;padding-left:5px;"><a href="EditPostsright.do?id=<%=rs2.getString(1) %>">编辑</a></td>	
				<td style="word-break:keep-all; border-bottom: #6666cc 1px dashed;"><a href="DeletePostsright.do?id=<%=rs2.getString(1) %>" onClick="delcfm()">删除</a></td>	
			</tr>
<%
				rs2.next(); 
				i++; 
		
			}rs2.close(); 
			i=0; 	
		} 
		else{ 	
			out.print("<br /><center><table border=0 align=center cellpadding=0 cellspacing=1 ><tr><td><center>目前还没有内容！</center></td></tr></table></centre><br />"); 
		}		%> 
	</table> 
	</div>
	<div style="margin-top:5px;margin-bottom:2px;">	
	<table width="100%"  align="center" cellpadding="0" cellspacing="1" > 
	<tr> 
	<td height="22" align="center" >
	<% 
		if(intPage<2){ 
			out.print("首页 | 上一页"); 
		}else{	%> 
			<a href="./admin_postsright.jsp">首页 </a> | <a href="./admin_postsright.jsp?page=<%=intPage-1%>">上一页</a> 
		<%}%> 
	| 
	<% 
		if((intPageCount-intPage)<1) { 
			out.print("下一页 | 尾页"); 
		}else{%> 
			<a href="./admin_postsright.jsp?page=<%=intPage+1%>">下一页</a> | <a href="./admin_postsright.jsp?page=<%=intPageCount%>">尾页</a> 
		<%} %>
	
		共<%=intRowCount%>条记录    第<%=intPage%>页/共<%=intPageCount%>页 
		<form action="./admin_postsright.jsp" method="post" style="display:inline;" >
	    	<input type="text" size="2" name="page" id="page" onblur="checkPage();">页
	    	<input type="button" value="GO" onclick="register_Page(this.form);" />
		</form>
		<a style="margin-left:30px;" href="AddEditPostsright.do">发布文章</a>
		<a style="margin-left:30px;" href="EditPostsrightListName.do">列表名称设置</a>
	
	</td></tr></table>	
	</div>
</div>
		
<%		
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	} catch (InstantiationException e) {
	    e.printStackTrace();
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (SQLException e) {
		e.printStackTrace();
	} 
	finally {
		if (rs1 != null) {
			rs1.close();
			rs1 = null;
		}
		if (rs2 != null) {
			rs2.close();
			rs2 = null;
		}
		if (pstmt1 != null) {
			pstmt1.close();
			pstmt1 = null;
		}
		if (pstmt2 != null) {
			pstmt2.close();
			pstmt2 = null;
		}		
		if (conn != null) {
			conn.close();
			conn = null;
		}
	}
%>

</body>
</html>